﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL.BusinessRules;

namespace BLL
{
    public abstract class BusinessObject
    {
        protected static readonly string versionDefault = "NotSet";
        private IList<BusinessRule> businessRules = new List<BusinessRule>();
        private IList<string> validationErrors = new List<string>();

        public IList<string> ValidationErrors
        {
            get { return validationErrors; }
        }

        protected void AddRule(BusinessRule rule)
        {
            businessRules.Add(rule);
        }

        public bool Validate()
        {
            bool isValid = true;
            validationErrors.Clear();
            foreach (BusinessRule rule in businessRules)
            {
                if (!rule.Validate(this))
                {
                    isValid = false;
                    ValidationErrors.Add(rule.ErrorMessage);
                }
            }
            return isValid;
        }
    }
}
